package server.business.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import server.business.mapper.TransfusionReviewMapper;
import server.business.pojo.TransfusionClinic;
import server.business.pojo.TransfusionReview;
import server.business.pojo.TransfusionSurgey;
import server.business.service.TransfusionSurgeyService;
import server.business.mapper.TransfusionSurgeyMapper;
import org.springframework.stereotype.Service;
import server.business.service.TransfusionTypeService;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Galaxy
 * @description 针对表【transfusion_surgey】的数据库操作Service实现
 * @createDate 2022-11-08 12:46:25
 */
@Service("transfusionSurgeyService")
public class TransfusionSurgeyServiceImpl extends ServiceImpl<TransfusionSurgeyMapper, TransfusionSurgey>
        implements TransfusionSurgeyService {
    @Autowired
    private TransfusionSurgeyMapper transfusionSurgeyMapper;
    @Autowired
    private TransfusionReviewMapper transfusionReviewMapper;

    @Override
    public int tranSurgeyAdd(TransfusionSurgey transfusionSurgey) {
        int tranClinicCreate = transfusionSurgeyMapper.insert(transfusionSurgey);
        return tranClinicCreate;
    }

    /**
     * 展示术中输血信息
     * 
     * @param transfusionNumber
     * @return
     */
    @Override
    public ArrayList<Object> getSurInfo(String transfusionNumber) {
        return transfusionSurgeyMapper.showSur(transfusionNumber);
    }

    /**
     * 批量逻辑删除
     * 
     * @param ids
     * @return
     */
    @Override
    public ArrayList<Long> selectId(ArrayList<Long> ids) {

        ArrayList<String> list = new ArrayList<>();
        for (Long id : ids) {
            QueryWrapper<TransfusionReview> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(TransfusionReview::getId, id);
            TransfusionReview t = transfusionReviewMapper.selectOne(queryWrapper);
            System.out.println(t.getTransfusionNumber());
            list.add(t.getTransfusionNumber());
            System.out.println(list);
        }

        ArrayList<Long> list1 = new ArrayList<>();
        for (String transfusionNumber : list) {
            QueryWrapper<TransfusionSurgey> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.lambda().eq(TransfusionSurgey::getTransfusionNumber, transfusionNumber);
            TransfusionSurgey t1 = transfusionSurgeyMapper.selectOne(queryWrapper1);
            System.out.println(t1.getId());
            list1.add(t1.getId());
        }

        return list1;

    }

    // *************************************lrz*************************start
    /**
     *
     * @param currentPage
     * @param pageSize
     * @param bloodInformation
     * @return
     */
    @Override
    @SuppressWarnings("")
    public IPage<TransfusionSurgey> getPage1(int currentPage, int pageSize,
            TransfusionSurgey transfusionSurgey) {
        LambdaQueryWrapper<TransfusionSurgey> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                .eq(Strings.isNotBlank(transfusionSurgey.getTransfusionNumber()),
                        TransfusionSurgey::getTransfusionNumber,
                        transfusionSurgey.getTransfusionNumber())
                .eq(Strings.isNotBlank(transfusionSurgey.getAboBloodType()),
                        TransfusionSurgey::getAboBloodType,
                        transfusionSurgey.getAboBloodType())
                .eq(Strings.isNotBlank(transfusionSurgey.getTransfusionType()),
                        TransfusionSurgey::getTransfusionType,
                        transfusionSurgey.getTransfusionType())
                .eq(Strings.isNotBlank(transfusionSurgey.getPatientIdcard()),
                        TransfusionSurgey::getPatientIdcard,
                        transfusionSurgey.getPatientIdcard())
                .eq(Strings.isNotBlank(transfusionSurgey.getTransfusionVolume()),
                        TransfusionSurgey::getTransfusionVolume,
                        transfusionSurgey.getTransfusionVolume())
                .eq(Strings.isNotBlank(transfusionSurgey.getRhBloodType()),
                        TransfusionSurgey::getRhBloodType,
                        transfusionSurgey.getRhBloodType());
        IPage<TransfusionSurgey> page = new Page<>(currentPage, pageSize);
        transfusionSurgeyMapper.selectPage(page, queryWrapper);
        return page;
    }
    // *************************************lrz*************************end

}
